//
//  HeartRateCharView.m
//  JiuLe
//
//  Created by 黄鑫 on 16/9/13.
//  Copyright © 2016年 Fine. All rights reserved.
//

#import "HeartRateCharView.h"

@implementation HeartRateCharView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.width -100)];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        viewH                = [UIScreen mainScreen].bounds.size.width ;
        viewW                = [UIScreen mainScreen].bounds.size.width;
        self.chartH      =        viewH - 210;
        self.chartw      =        viewW - 40;
    }
    return self;
}

- (CGRect)getGraphicPositionget:(NSString *)number index:(int)i{
    float yCoordinate ;
    if([number isEqualToString:@"0"]){
        yCoordinate  = self.chartY + self.chartH;
    }else{
        yCoordinate  = self.chartY + self.chartH - ([number intValue]*self.percentage);//5 为单位比例yInterval/每条线代表的单位
    }
    float xCoordinate;
    if(self.baseChartShowDate == BaseChartShowDateDay){
        xCoordinate = self.chartX + (i * (self.chartw/288.0));
    }else if (self.baseChartShowDate == BaseChartShowDateWeek){
        xCoordinate = self.chartX + (i * (self.chartw/6));
    }else{
        xCoordinate = self.chartX + (i * (self.chartw/28));
    }
    if(CGRectGetWidth(self.frame) > 320){
        if(self.baseChartType == BaseChartTypeLineChart){
            return CGRectMake(xCoordinate - (CircleDiameter/2), yCoordinate - CircleDiameter+2, CircleDiameter, CircleDiameter);
        }else{
            return CGRectMake(xCoordinate - (RectangleWidth/2), yCoordinate - (RectangleWidth/2) +2.5, RectangleWidth, self.chartY + self.chartH - yCoordinate);
        }
    }else{
        if(self.baseChartType == BaseChartTypeLineChart){
            return CGRectMake(xCoordinate - (CircleDiameter/2), yCoordinate - CircleDiameter + 0.7, CircleDiameter, CircleDiameter);
        }else{
            return CGRectMake(xCoordinate - (RectangleWidth/2), yCoordinate - (RectangleWidth/2)+2, RectangleWidth, self.chartY + self.chartH - yCoordinate);
        }
    }

}

@end
